AC_DEFUN([AC_GROWL],
[
AC_ARG_WITH([growl],
            AS_HELP_STRING([--with-growl=prefix],
                           [specify growl SDK prefix]),
            [ac_growl_prefix="$withval"])

AC_ARG_VAR([GROWL_CFLAGS],  [C compiler flags for growl(default is -framework Growl)])
AC_ARG_VAR([GROWL_LDFLAGS], [linker flags for growl(default is -framework Growl -framework Carbon)])

if test "$GROWL_CFLAGS" = ""; then
  GROWL_CFLAGS="-framework Growl"
fi
if test "$GROWL_LDFLAGS" = ""; then
  GROWL_LDFLAGS="-framework Growl -framework Carbon"
fi
if test "$ac_growl_prefix" != ""; then
  GROWL_CFLAGS="-F$ac_growl_prefix $GROWL_CFLAGS"
  GROWL_LDFLAGS="-Wl,-F$ac_growl_prefix $GROWL_LDFLAGS"
fi

CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $GROWL_CFLAGS"
export CPPFLAGS

LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $GROWL_LDGLAGS"
export LDFLAGS

AC_LANG_PUSH([C])
AC_CHECK_HEADER([Growl/Growl.h], [
AC_MSG_CHECKING([for Growl])
AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[
@%:@include <Growl/Growl.h>
]], [[
struct Growl_Delegate delegate;
InitGrowlDelegate(&delegate);
Growl_SetDelegate(&delegate);
struct Growl_Notification n;
InitGrowlNotification(&n);
Growl_PostNotification(&n);
]]),
[AC_MSG_RESULT([yes])
 ifelse([$1], , :, [$1])],
[AC_MSG_RESULT([no])
 ifelse([$2], , :, [$2])])
], ifelse([$2], , :, [$2]))
AC_LANG_POP([C])

CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"

AC_SUBST(GROWL_CFLAGS)
AC_SUBST(GROWL_LDFLAGS)
])
